package com.zq.assistant.utils;

import android.content.Context;
import android.support.v4.widget.PopupWindowCompat;
import android.support.v7.widget.ListPopupWindow;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;

import com.zq.assistant.R;

import java.util.List;

/**
 * Created by zhangqiang on 17-5-23.
 */

public class DialogUtils {

    public static ListPopupWindow showList(Context context, View anchorView, List<String> items, AdapterView.OnItemClickListener onItemClickListener) {

        ListPopupWindow listPopupWindow = new ListPopupWindow(context);
        listPopupWindow.setAnchorView(anchorView);
        listPopupWindow.setModal(true);
        listPopupWindow.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, items));
        listPopupWindow.setDropDownGravity(Gravity.CENTER);
        listPopupWindow.setVerticalOffset(-anchorView.getHeight() / 2);
        listPopupWindow.setHorizontalOffset(anchorView.getWidth() / 2);
        listPopupWindow.setOnItemClickListener(onItemClickListener);
        listPopupWindow.show();
        return listPopupWindow;
    }
}
